package org.gap.dao;

import java.util.Arrays;
import java.util.HashSet;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.EntityManager;
import javax.persistence.NoResultException;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

import org.gap.domain.Patient;

import org.skyway.spring.util.dao.AbstractJpaDao;

import org.springframework.dao.DataAccessException;

import org.springframework.stereotype.Repository;

import org.springframework.transaction.annotation.Transactional;

/**
 * DAO to manage Patient entities.
 * 
 */
@Repository("PatientDAO")
@Transactional
public class PatientDAOImpl extends AbstractJpaDao<Patient> implements
		PatientDAO {

	/**
	 * Set of entity classes managed by this DAO.  Typically a DAO manages a single entity.
	 *
	 */
	private final static Set<Class<?>> dataTypes = new HashSet<Class<?>>(Arrays.asList(new Class<?>[] { Patient.class }));

	/**
	 * EntityManager injected by Spring for persistence unit 
	 *
	 */
	@PersistenceContext(unitName = "")
	private EntityManager entityManager;

	/**
	 * Instantiates a new PatientDAOImpl
	 *
	 */
	public PatientDAOImpl() {
		super();
	}

	/**
	 * Get the entity manager that manages persistence unit 
	 *
	 */
	public EntityManager getEntityManager() {
		return entityManager;
	}

	/**
	 * Returns the set of entity classes managed by this DAO.
	 *
	 */
	public Set<Class<?>> getTypes() {
		return dataTypes;
	}

	/**
	 * JPQL Query - findPatientByPatDateEntree
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateEntree(java.util.Calendar patDateEntree) throws DataAccessException {

		return findPatientByPatDateEntree(patDateEntree, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateEntree
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateEntree(java.util.Calendar patDateEntree, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateEntree", startResult, maxRows, patDateEntree);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatAxeMedicalContaining
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatAxeMedicalContaining(String patAxeMedical) throws DataAccessException {

		return findPatientByPatAxeMedicalContaining(patAxeMedical, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatAxeMedicalContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatAxeMedicalContaining(String patAxeMedical, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatAxeMedicalContaining", startResult, maxRows, patAxeMedical);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateSortieBefore
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateSortieBefore(java.util.Calendar patDateSortie) throws DataAccessException {

		return findPatientByPatDateSortieBefore(patDateSortie, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateSortieBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateSortieBefore(java.util.Calendar patDateSortie, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateSortieBefore", startResult, maxRows, patDateSortie);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatMotifSortie
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatMotifSortie(String patMotifSortie) throws DataAccessException {

		return findPatientByPatMotifSortie(patMotifSortie, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatMotifSortie
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatMotifSortie(String patMotifSortie, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatMotifSortie", startResult, maxRows, patMotifSortie);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatSousAxeMedicalContaining
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatSousAxeMedicalContaining(String patSousAxeMedical) throws DataAccessException {

		return findPatientByPatSousAxeMedicalContaining(patSousAxeMedical, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatSousAxeMedicalContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatSousAxeMedicalContaining(String patSousAxeMedical, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatSousAxeMedicalContaining", startResult, maxRows, patSousAxeMedical);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatMotifSortieContaining
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatMotifSortieContaining(String patMotifSortie) throws DataAccessException {

		return findPatientByPatMotifSortieContaining(patMotifSortie, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatMotifSortieContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatMotifSortieContaining(String patMotifSortie, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatMotifSortieContaining", startResult, maxRows, patMotifSortie);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisiteBefore
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisiteBefore(java.util.Calendar patDateDerniereVisite) throws DataAccessException {

		return findPatientByPatDateDerniereVisiteBefore(patDateDerniereVisite, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisiteBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisiteBefore(java.util.Calendar patDateDerniereVisite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateDerniereVisiteBefore", startResult, maxRows, patDateDerniereVisite);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDiagnosticContaining
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDiagnosticContaining(String patDiagnostic) throws DataAccessException {

		return findPatientByPatDiagnosticContaining(patDiagnostic, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDiagnosticContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDiagnosticContaining(String patDiagnostic, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDiagnosticContaining", startResult, maxRows, patDiagnostic);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatPatient
	 *
	 */
	@Transactional
	public Patient findPatientByPatPatient(Integer patPatient) throws DataAccessException {

		return findPatientByPatPatient(patPatient, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatPatient
	 *
	 */

	@Transactional
	public Patient findPatientByPatPatient(Integer patPatient, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findPatientByPatPatient", patPatient);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findAllPatients
	 *
	 */
	@Transactional
	public Set<Patient> findAllPatients() throws DataAccessException {

		return findAllPatients(-1, -1);
	}

	/**
	 * JPQL Query - findAllPatients
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findAllPatients(int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findAllPatients", startResult, maxRows);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisite
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisite(java.util.Calendar patDateDerniereVisite) throws DataAccessException {

		return findPatientByPatDateDerniereVisite(patDateDerniereVisite, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisite
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisite(java.util.Calendar patDateDerniereVisite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateDerniereVisite", startResult, maxRows, patDateDerniereVisite);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPrimaryKey
	 *
	 */
	@Transactional
	public Patient findPatientByPrimaryKey(Integer patPatient) throws DataAccessException {

		return findPatientByPrimaryKey(patPatient, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPrimaryKey
	 *
	 */

	@Transactional
	public Patient findPatientByPrimaryKey(Integer patPatient, int startResult, int maxRows) throws DataAccessException {
		try {
			return executeQueryByNameSingleResult("findPatientByPrimaryKey", patPatient);
		} catch (NoResultException nre) {
			return null;
		}
	}

	/**
	 * JPQL Query - findPatientByPatTelContact
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatTelContact(Integer patTelContact) throws DataAccessException {

		return findPatientByPatTelContact(patTelContact, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatTelContact
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatTelContact(Integer patTelContact, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatTelContact", startResult, maxRows, patTelContact);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateSortie
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateSortie(java.util.Calendar patDateSortie) throws DataAccessException {

		return findPatientByPatDateSortie(patDateSortie, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateSortie
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateSortie(java.util.Calendar patDateSortie, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateSortie", startResult, maxRows, patDateSortie);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisiteAfter
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisiteAfter(java.util.Calendar patDateDerniereVisite) throws DataAccessException {

		return findPatientByPatDateDerniereVisiteAfter(patDateDerniereVisite, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateDerniereVisiteAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateDerniereVisiteAfter(java.util.Calendar patDateDerniereVisite, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateDerniereVisiteAfter", startResult, maxRows, patDateDerniereVisite);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDivers
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDivers(String patDivers) throws DataAccessException {

		return findPatientByPatDivers(patDivers, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDivers
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDivers(String patDivers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDivers", startResult, maxRows, patDivers);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatAxeMedical
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatAxeMedical(String patAxeMedical) throws DataAccessException {

		return findPatientByPatAxeMedical(patAxeMedical, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatAxeMedical
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatAxeMedical(String patAxeMedical, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatAxeMedical", startResult, maxRows, patAxeMedical);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDiversContaining
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDiversContaining(String patDivers) throws DataAccessException {

		return findPatientByPatDiversContaining(patDivers, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDiversContaining
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDiversContaining(String patDivers, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDiversContaining", startResult, maxRows, patDivers);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateSortieAfter
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateSortieAfter(java.util.Calendar patDateSortie) throws DataAccessException {

		return findPatientByPatDateSortieAfter(patDateSortie, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateSortieAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateSortieAfter(java.util.Calendar patDateSortie, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateSortieAfter", startResult, maxRows, patDateSortie);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatSousAxeMedical
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatSousAxeMedical(String patSousAxeMedical) throws DataAccessException {

		return findPatientByPatSousAxeMedical(patSousAxeMedical, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatSousAxeMedical
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatSousAxeMedical(String patSousAxeMedical, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatSousAxeMedical", startResult, maxRows, patSousAxeMedical);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDiagnostic
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDiagnostic(String patDiagnostic) throws DataAccessException {

		return findPatientByPatDiagnostic(patDiagnostic, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDiagnostic
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDiagnostic(String patDiagnostic, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDiagnostic", startResult, maxRows, patDiagnostic);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateEntreeAfter
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateEntreeAfter(java.util.Calendar patDateEntree) throws DataAccessException {

		return findPatientByPatDateEntreeAfter(patDateEntree, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateEntreeAfter
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateEntreeAfter(java.util.Calendar patDateEntree, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateEntreeAfter", startResult, maxRows, patDateEntree);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * JPQL Query - findPatientByPatDateEntreeBefore
	 *
	 */
	@Transactional
	public Set<Patient> findPatientByPatDateEntreeBefore(java.util.Calendar patDateEntree) throws DataAccessException {

		return findPatientByPatDateEntreeBefore(patDateEntree, -1, -1);
	}

	/**
	 * JPQL Query - findPatientByPatDateEntreeBefore
	 *
	 */

	@SuppressWarnings("unchecked")
	@Transactional
	public Set<Patient> findPatientByPatDateEntreeBefore(java.util.Calendar patDateEntree, int startResult, int maxRows) throws DataAccessException {
		Query query = createNamedQuery("findPatientByPatDateEntreeBefore", startResult, maxRows, patDateEntree);
		return new LinkedHashSet<Patient>(query.getResultList());
	}

	/**
	 * Used to determine whether or not to merge the entity or persist the entity when calling Store
	 * @see store
	 * 
	 *
	 */
	public boolean canBeMerged(Patient entity) {
		return true;
	}
}
